package js.dwim.client;

import js.dwim.client.domain.GameWorld;

public class GameState
{
    public static final String SERVER_NAME  = "js-testsite@appspot.com";
    public static final String HOST_NAME    = "talk.google.com";
    public static final int    HOST_PORT    = 443;
    public static final String HOST_SERVICE = "gmail.com";
    
    private XmppComms   comm    = null;
    private GameWorld   world   = null;
    private GameSurface surface = null;

    public GameState( GameSurface surface ) throws CommunicationException
    {
        this.surface = surface;
        
        comm = new XmppComms( SERVER_NAME, HOST_NAME, HOST_PORT, HOST_SERVICE );
    }
    
    public boolean isConnected()
    {
        return comm.isConnected();
    }
    
    public void connect(String user, String pwd) 
            throws CommunicationException, InterruptedException
    {
        comm.login( user, pwd );
    }

    public void disconnect()
    {
        comm.disconnect();
    }
    
    public void sendRawMessage( String msg ) throws CommunicationException
    {
        comm.sendRawMessage( msg );
    }
    
    public String getReply( String msg ) 
            throws CommunicationException, InterruptedException
    {
        return comm.getReply( msg );
    }
    
    public void addMessageReceiver( IMessageReceiver receiver )
    {
        comm.addMessageReceiver( receiver );
    }
    
    public void initGame() 
            throws CommunicationException, InterruptedException, ParserException
    {
        this.world = ParserUtils.parseWorld( comm.getReply( "/score" ) );
    }

    public GameSurface getSurface()
    {
        return surface;
    }

    public GameWorld getWorld()
    {
        return world;
    }
}
